﻿
    using System;
    using Cysharp.Threading.Tasks;
    using FpFrame;
    using Unity.VisualScripting;
    using UnityEngine;

    namespace FpFrame
    {
        public partial class UIEventType
        {
            public static readonly UIEventType Start = new UIEventType("Start");
            public static readonly UIEventType Game = new UIEventType("Game");
            public static readonly UIEventType HpChange = new UIEventType("HpChange");
        }
    }
    
  
    [Serializable]
    public class PlayerConfig
    {
        public string ip;
        public int port;
        public int maxHealth;
    }
    
    public class GameFlowManager : ModuleManager
    {
        ConfigManager configManager;
        GameUIManager gameUIManager;

        public override async UniTask InitAsync()
        {
            configManager = resolver.Resolve<ConfigManager>();
            gameUIManager = resolver.Resolve<GameUIManager>();

            EventBus.Subscribe<UIEvent>(OnClickButtonClick);
            await UniTask.Yield();

           // _ = gameUIManager.Show<StartPanel>();
           
           Debug.Log("执行了开始的方法");
        }

        private async void OnClickButtonClick(UIEvent obj)
        {
            if (obj.Type == UIEventType.ReturnHome)
            {
                _ = gameUIManager.Show<StartPanel>();
            }
            else if (obj.Type == UIEventType.Start)
            {
                _ = gameUIManager.Show<GamePanelu>();
                
                // var data = await  configManager.LoadAsync<PlayerConfig>();
                // FDebug.Log($"{data.ip}:{data.port}");
            }
            else if (obj.Type == UIEventType.Game)
            {
                _ = gameUIManager.Show<FinishPanel>();
            }
        }
    }
